unit LT_Category;

interface
uses PluginElems, SysUtils;
type
  TLT_Category=class
  private
    FUID: TLT_UID;
    FTitle:PWideChar;
    FGrouped:Boolean;
    FFavorite:Boolean;
    FComment:PWideChar;
    FCreateDate:TDateTime;
    FParentUID:TLT_UID;
    function getTitle: PWideChar;
    procedure setTitle(const Value: PWideChar);
    function getGrouped: Boolean;
    procedure setGrouped(const Value: Boolean);
    function getFavorite: Boolean;
    procedure setFavorite(const Value: Boolean);
    function getComment: PWideChar;
    procedure setComment(const Value: PWideChar);
    function getCreateDate: TDateTime;
    function getParentUID: TLT_UID;
    procedure setParentUID(const Value: TLT_UID);
    function getChildsCount: Integer;
    public
      function isExists():Boolean;
      constructor Create(uid:TLT_UID);
      function getChildUID(number:integer):TLT_UID;
      function Save():TLT_UID;
      function Delete():Boolean;
      property uid:TLT_UID read FUID write FUID;
      property title:PWideChar read getTitle write setTitle;
      //property order:Integer read getOrder write setOrder;
      //property color:DWORD read getColor write setColor;
      property grouped:Boolean read getGrouped write setGrouped;
      property favorite:Boolean read getFavorite write setFavorite;
      property comment:PWideChar read getComment write setComment;
      property createDate:TDateTime read getCreateDate;
      property parentUID:TLT_UID read getParentUID write setParentUID;
      property childsCount:Integer read getChildsCount;

  end;
implementation

{ TLT_Category }

constructor TLT_Category.Create(uid: TLT_UID);
begin
  FUID:=uid;
  FTitle:='';
  FGrouped:=false;
  FFavorite:=false;
  FComment:='';
  FCreateDate:=getTime();
  FParentUID:='';
end;

function TLT_Category.Delete: Boolean;
begin
  if isExists then
    Result:=AddinLT_Category_Delete(uid)
  else
    Result:=false;
end;

function TLT_Category.getChildsCount: Integer;
begin
  if isExists then
    Result:=AddinLT_Category_GetChildsCount(uid)
  else
    Result:=0;
end;

function TLT_Category.getChildUID(number: integer): TLT_UID;
begin
  if isExists then
    Result:=AddinLT_Category_GetChildUID(uid,number)
  else
    Result:=nil;
end;

function TLT_Category.getComment: PWideChar;
begin
  if isExists then
    Result:=AddinLT_Category_GetCommentText(uid)
  else
    Result:=FComment;
end;

function TLT_Category.getCreateDate: TDateTime;
begin
  if isExists then
    Result:=AddinLT_Category_GetDateCreate(uid)
  else
    Result:=FCreateDate;
end;

function TLT_Category.getFavorite: Boolean;
begin
  if isExists then
    Result:=AddinLT_Category_IsFavorite(uid)
  else
    Result:=FFavorite;
end;

function TLT_Category.getGrouped: Boolean;
begin
  if isExists then
    Result:=AddinLT_Category_IsGrouped(uid)
  else
    Result:=FGrouped;
end;

function TLT_Category.getParentUID: TLT_UID;
begin
  if isExists then
    Result:=AddinLT_Category_GetParentUID(uid)
  else
    Result:=FParentUID;
end;

function TLT_Category.getTitle: PWideChar;
begin
  if isExists then
    Result:=AddinLT_Category_GetTitle(uid)
  else
    Result:=FTitle;
end;

function TLT_Category.isExists: Boolean;
begin
  if (uid=nil) and (WideCharToString(uid)='') then
    Result:=false
  else
    Result:=AddinLT_Category_IsPresent(uid);
end;

function TLT_Category.Save: TLT_UID;
begin
  if isExists then
  begin
    AddinLT_Category_SaveChanges(uid);
  end else
  begin
    FUID:=AddinLT_Category_Insert(uid, parentUID, title, createDate);
    comment:=FComment;
  end;
  Result:=uid;
end;

procedure TLT_Category.setComment(const Value: PWideChar);
begin
  if isExists then
    AddinLT_Category_SetCommentText(uid, Value)
  else
    FComment:=Value;
end;

procedure TLT_Category.setFavorite(const Value: Boolean);
begin
  if isExists then
    AddinLT_Category_SetFavorite(uid,Value)
  else
    FFavorite:=Value;
end;

procedure TLT_Category.setGrouped(const Value: Boolean);
begin
  if isExists then
    AddinLT_Category_SetGrouped(uid,Value)
  else
    FGrouped:=Value;
end;

procedure TLT_Category.setParentUID(const Value: TLT_UID);
begin
  if isExists then
    AddinLT_Category_SetParentUID(uid,Value)
  else
    FParentUID:=Value;
end;

procedure TLT_Category.setTitle(const Value: PWideChar);
begin
  if isExists then
    AddinLT_Category_SetTitle(uid, Value)
  else
    FTitle:=Value;
end;

end.
